package com.penghaisoft.microwms.task.test;

import com.penghaisoft.microwms.common.base.model.BaseUser;
import com.penghaisoft.microwms.task.material.service.IDemoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 定时任务
 * Created by zxcq0 on 2017/4/27.
 */
@Slf4j
@Component
public class ScheduledTasks {

    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Autowired
    private IDemoService demoService;

    /**
     * 每次间隔5秒
     * 必须加上EnableScheduling才行
     */
    @Scheduled(fixedRate = 5000)
    public void reportCurrentTime() {
        log.info("-----fixedRate------The time is now {}", sdf.format(new Date()));
        BaseUser cond = new BaseUser();
        cond.setLoginName("zhangxu");
        BaseUser result = demoService.queryOne(cond);
        System.out.println(result.getLoginName());
        log.info("-----fixedRate------END");
    }

    @Scheduled(cron = "0/10 * * * * *")
    public void reportCron() {
        log.info("-----cron------The time is now {}", sdf.format(new Date()));
        log.info("-----cron------END");
    }
}
